package com.vecspace.dayu.code.pojo;

import java.util.Date;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.vecspace.data.model.IdEntity;
import com.vecspace.data.model.RowMapper;
import com.vecspace.dicttable.DictAll;

import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.annotations.Polymorphism;
import org.hibernate.annotations.PolymorphismType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/** DAYU-项目定义
 * @author wanghua
 */
@Entity
@Polymorphism(type = PolymorphismType.EXPLICIT)
@Table(name = "DAYU_CODE_PROJECT")
public class Project implements IdEntity, java.io.Serializable {
	private static final long serialVersionUID = -5206786901654072938L;
	public Project(){
	}
	
	private Long id;
	/**逻辑ID*/
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name = "ID")
	public Long getId(){
		return id;
	}
	/**逻辑ID*/
	public void setId(Long value){
		this.id = value;
	}

	private String name;
	/**功能名称*/
	@Column(name = "NAME_")
	public String getName(){
		return name;
	}
	/**功能名称*/
	public void setName(String value){
		this.name = value;
	}

	private String code;
	/**功能名称*/
	@Column(name = "CODE_")
	public String getCode(){
		return code;
	}
	/**功能名称*/
	public void setCode(String value){
		this.code = value;
	}

	private Long catalogId;
	/**分组ID*/
	@Column(name = "CATALOG_ID")
	public Long getCatalogId(){
		return catalogId;
	}
	/**分组ID*/
	public void setCatalogId(Long value){
		this.catalogId = value;
	}

	private String dbType;
	/**数据库类型*/
	@Column(name = "DB_TYPE")
	public String getDbType(){
		return dbType;
	}
	/**数据库类型*/
	public void setDbType(String value){
		this.dbType = value;
	}
	public static String DbTypeCode = "DAYU-CODE-008";
	/**数据库类型*/
	@Transient
	public String getDbTypeCaption(){
		return DictAll.getCachedItemName(DbTypeCode, dbType);
	}
	
	private String dbSchema;
	/**数据库名*/
	@Column(name = "DB_SCHEMA")
	public String getDbSchema(){
		return dbSchema;
	}
	/**数据库名*/
	public void setDbSchema(String value){
		this.dbSchema = value;
	}

	private String dbUser;
	/**数据库用户名*/
	@Column(name = "DB_USER")
	public String getDbUser(){
		return dbUser;
	}
	/**数据库用户名*/
	public void setDbUser(String value){
		this.dbUser = value;
	}

	private String dbPasswd;
	/**数据库密码*/
	@Column(name = "DB_PASSWD")
	public String getDbPasswd(){
		return dbPasswd;
	}
	/**数据库密码*/
	public void setDbPasswd(String value){
		this.dbPasswd = value;
	}

	private String pdmFilePath;
	/**PDM文件，上传后存储的文件名*/
	@Column(name = "PDM_FILE_PATH")
	public String getPdmFilePath(){
		return pdmFilePath;
	}
	/**PDM文件，上传后存储的文件名*/
	public void setPdmFilePath(String value){
		this.pdmFilePath = value;
	}


	private String pdmFileName;
	/**PDM文件 上传前的文件名*/
	@Column(name = "PDM_FILE_NAME")
	public String getPdmFileName(){
		return pdmFileName;
	}
	/**PDM文件 上传前的文件名*/
	public void setPdmFileName(String value){
		this.pdmFileName = value;
	}


	private Date pdmFileUploadTime;
	/**PDM文件*/
	@Column(name = "PDM_FILE_UPLOAD_TIME")
	public Date getPdmFileUploadTime(){
		return pdmFileUploadTime;
	}
	/**PDM文件*/
	public void setPdmFileUploadTime(Date value){
		this.pdmFileUploadTime = value;
	}

	private String pdmFileUploader;
	/**PDM文件*/
	@Column(name = "PDM_FILE_UPLOADER")
	public String getPdmFileUploader(){
		return pdmFileUploader;
	}
	/**PDM文件*/
	public void setPdmFileUploader(String value){
		this.pdmFileUploader = value;
	}
	
	private Integer ordnum;
	/**顺序号*/
	@Column(name = "ORDNUM")
	public Integer getOrdnum(){
		return ordnum;
	}
	/**顺序号*/
	public void setOrdnum(Integer value){
		this.ordnum = value;
	}

	private Date createTime;
	/**记录创建时间*/
	@JsonIgnore(true)
	@Column(name = "CREATE_TIME")
	public Date getCreateTime(){
		return createTime;
	}
	/**记录创建时间*/
	public void setCreateTime(Date value){
		this.createTime = value;
	}
	@Transient
	@JsonIgnore(true)
	public String getCreateTimeStr(){
		if(createTime == null){
			return "";
		}
		String exp = "yyyy-MM-dd";
		String timestr = new java.text.SimpleDateFormat(exp).format(createTime);
		return timestr;
	}

	private String createUser;
	/**记录创建人ID*/
	@Column(name = "CREATE_USER")
	public String getCreateUser(){
		return createUser;
	}
	/**记录创建人ID*/
	public void setCreateUser(String value){
		this.createUser = value;
	}

	public void parseFrom(Map<String, Object> row){
		RowMapper rowMapper = new RowMapper(row);
		this.id = rowMapper.getLong("ID");
		this.name = rowMapper.getString("NAME_");
		this.code = rowMapper.getString("CODE_");
		this.dbType = rowMapper.getString("DB_TYPE");
		this.dbSchema = rowMapper.getString("DB_SCHEMA");
		this.dbUser = rowMapper.getString("DB_USER");
		this.dbPasswd = rowMapper.getString("DB_PASSWD");
		this.pdmFilePath = rowMapper.getString("PDM_FILE_PATH");
		this.pdmFileName = rowMapper.getString("PDM_FILE_NAME");
		this.pdmFileUploadTime = rowMapper.getDate("PDM_FILE_UPLOAD_TIME");
		this.pdmFileUploader = rowMapper.getString("PDM_FILE_UPLOADER");
		this.ordnum = rowMapper.getInteger("ORDNUM");
		this.createTime = rowMapper.getDate("CREATE_TIME");
		this.createUser = rowMapper.getString("CREATE_USER");
		this.catalogId = rowMapper.getLong("CATALOG_ID");
	}

	@Override
	public boolean equals(Object obj) {
		if(obj == null)return false;
		if(id == null)return false;
		Project other = (Project)obj;
		return id.equals(other.id);
	}

	@Override
	public int hashCode() {
		if(id == null)return 0;
		return id.hashCode();
	}
}
